﻿using Acme.BookStore.Authors;
using Acme.BookStore.Books;
using Acme.BookStore.Identity;
using AutoMapper;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Data;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;

namespace Acme.BookStore;

public class BookStoreApplicationAutoMapperProfile : Profile
{
    public BookStoreApplicationAutoMapperProfile()
    {
        /* You can configure your AutoMapper mapping configuration here.
         * Alternatively, you can split your mapping configurations
         * into multiple profile classes for a better organization. */


        CreateMap<Book, BookDto>();
        CreateMap<CreateUpdateBookDto, Book>();

        CreateMap<Author, AuthorDto>();

        CreateMap<Author, AuthorLookupDto>();


        CreateMap<Book, BookCacheItem>();


        //ObjectExtensionManager.Instance
        //    .AddOrUpdate<CreateUpdateBookDto>(objConfig =>
        //    {
        //        objConfig.Validators.Add(context =>
        //        {
        //            if (context.ValidatingObject.GetProperty<string>("Name") !=
        //                context.ValidatingObject.GetProperty<string>("Description"))
        //            {
        //                context.ValidationErrors.Add(
        //                    new ValidationResult(
        //                        "Name and Description can not be the same!111",
        //                        new[] { "Name", "Description" }
        //                    )
        //                );
        //            }
        //        });
        //    });



        CreateMap<Volo.Abp.Identity.IdentityUserDto, IdentityUserAndRoleDto>();
    }
}
